<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 450px;
            height: 500px;
            background-color: #ebefff;
            margin: 100px auto;
            overflow: hidden;
        }

        .box .wen {
            width: 230px;
            height: 50px;
            margin: 40px auto;
        }

        .box .wen span {
            font-size: 40px;
            font-weight: bold;
            font-family: '楷体';
        }

        .box .wen img {
            vertical-align: bottom;
        }

        .box .ye {
            width: 420px;
            height: 300px;
            background-color: white;
            margin: 0 auto;
            border-radius: 5px;
            overflow: hidden;
        }

        input {
            width: 250px;
            height: 30px;
            margin: 10px 80px;
            background-color: #f7f7f7;
            border: 0;
            border-radius: 5px;

        }

        .box .zhu input {
            background-color: #a1bfff;
            color: white;
        }

        .zhuce {
            text-align: center;
            margin: 10px auto;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="wen"><img src="./03.gif" alt=""><span>阿里云盘</span></div>
        <div class="ye">
            <div class="zhuce">注册新账号</div>
            <div class="zi"><input type="text" placeholder="请输入账号"></div>
            <div class="zi"><input type="password" placeholder="请输入密码"></div>
            <div class="zi"><input type="password" placeholder="确认密码"></div>
            <div class="zhu"><input type="button" value="注册"></div>
        </div>
    </div>
</body>

</html>
<script src="./ajax.js"></script>
<script>

    var input = document.querySelectorAll('.box .ye input')
    input[3].onclick = function () {
        if (input[0].value && input[1].value) {
            if (/^\d{4}/.test(input[1].value)) {
                if (input[1].value == input[2].value) {
                    ajax('get', 'https://yantianfeng.com/api/register', { username: input[0].value, password: input[1].value }).then((data) => {
                        if (data.status == 400) {
                            alert(data.msg)
                        } else {
                            alert(data.msg)
                        }
                    })
                } else {
                    alert('密码不一致')
                }
            } else {
                alert('秘密不符合规则')
            }
        } else {
            alert('账号/密码不能为空')
        }
    }
</script>